package com.weichen.studentgameexchange.game.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.game.entity.Developer;
import com.weichen.studentgameexchange.game.service.IDeveloperService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * TODO 管理员-游戏--开发商管理
 */

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/game/developer")
public class DeveloperController {

    @Autowired
    IDeveloperService developerService;

    /**
     * 管理员添加开发商
     *
     * @param developer
     * @return
     */
    @Operation(summary = "管理员添加开发商接口")
    @PostMapping("/admin/add")
    public Result adminAdd(@RequestBody Developer developer) {
        return developerService.adminAdd(developer);
    }

    /**
     * 管理员分页查询开发商信息
     *
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询开发商信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam("keyword") String keyword,
                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        return developerService.adminPage(keyword, page, size);
    }

    /**
     * 管理员查看所有开发商信息
     *
     * @return
     */
    @Operation(summary = "管理员查看所有开发商信息接口")
    @GetMapping("/admin/selectAll")
    public Result adminselectAll() {
        return Result.success(developerService.list());
    }

    /**
     * 管理员查看单个开发商信息
     *
     * @param developerId
     * @return
     */
    @Operation(summary = "管理员查看单个开发商信息接口")
    @GetMapping("/admin/selectOne/{developerId}")
    public Result adminSelectOne(@PathVariable("developerId") Long developerId) {
        Developer developer = developerService.adminSelectOne(developerId);
        return Result.success(developer);
    }

    /**
     * 管理员修改开发商信息
     *
     * @param developer
     * @return
     */
    @Operation(summary = "管理员修改开发商信息接口")
    @PutMapping("/admin/update")
    public Result adminUpdate(@RequestBody Developer developer) {
        return developerService.adminUpdate(developer);
    }

    /**
     * 管理员删除单个开发商
     *
     * @param developerId
     * @return
     */
    @Operation(summary = "管理员删除单个开发商接口")
    @DeleteMapping("/admin/delete/{developerId}")
    public Result adminDeleteOne(@PathVariable("developerId") Long developerId) {
        developerService.adminDeleteOne(developerId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个开发商
     *
     * @param developerIds
     * @return
     */
    @Operation(summary = "管理员批量删除多个开发商接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> developerIds) {
        for (Long developerId : developerIds)
            adminDeleteOne(developerId);
        return Result.success();
    }
}
